<template>
  <div class="main">
    <div class="login">
      <div class="IconLogo">
        <i class="iconfont icon-wangyiyunyinle1-copy"></i>
      </div>
      <div class="form">
        <div class="item">
          <span class="iconfont icon-search"></span>
          <input type="text" placeholder="手机号码" v-model="phone" />
        </div>
        <div class="item">
          <span class="iconfont icon-search"></span>
          <input type="password" placeholder="密码" v-model="password" />
        </div>
        <div class="item">
          <span class="iconfont icon-search"></span>
          <input type="text" placeholder="验证码" v-model="code" />
          <button class="getCode" @click="getCode">发送</button>
        </div>
        <div class="item">
          <div class="submit" @click="submit">登录</div>
        </div>
      </div>
      <div class="SkipValidation">
        <div @click="SkipToNext">立即体验</div>
      </div>
      <div class="SwitchInputMode">
        <div class="iconfont icon-weixin"></div>
        <div class="iconfont icon-QQ"></div>
        <div class="iconfont icon-weibo"></div>
        <div class="iconfont icon-wangyi"></div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getLoginCellphone,
  // getUserDetail
} from "../../api/signin";
import { Toast } from "vant";
export default {
  data() {
    return {
      phone: "",
      password: "",
      code: "",
      Verificationmethod: "",
    };
  },
  methods: {
    SkipToNext() {
      this.$router.push("/recommend");
    },
    getCode() {
      // 1.验证手机号码
      let reg =
        /^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
      if (!reg.test(this.phone)) {
        Toast("请输入正确手机号码");
        return;
      }
      // 请求接口验证码
      // getCaptchaSent({ phone: this.phone }).then((data) => {
      //   if (data.data) {
      //     Toast("验证码发送成功");
      //   } else {
      //     Toast("验证码发送失败");
      //   }
      // });
    },
    submit() {
      // let regCode = /^[0-9]{4,6}$/;
      // // 验证码
      // if (!regCode.test(this.code)) {
      //   Toast("请输入正确验证码");
      //   return;
      // }
      // 1.验证手机号码
      let regPhone =
        /^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
      if (!regPhone.test(this.phone)) {
        Toast("请填写正确账号");
        return;
      }
      // 密码
      let regPassword = /^.{6,16}$/;
      if (!regPassword.test(this.password)) {
        Toast("请填写正确密码");
        return;
      }
      // getCaptchaVerify({ phone: this.phone, captcha: this.code })
      //   .then((data) => {
      //     if (data.data) {
            // 验证手机密码
            getLoginCellphone({
              phone: this.phone,
              password: this.password,
            }).then((info) => {
              console.log(info);
              Toast("登陆成功");
              window.localStorage.setItem("token", info.token);
              window.localStorage.setItem("uid", info.account.id);
              //登陆成功跳回个人中心页面
              // this.$router.push("/userInfo");
              console.log(info.account.id);
              this.$router.push("/userInfo",info.account.id);
            });
        //   } else {
        //     Toast("请填写正确信息");
        //   }
        // })
        // .catch(() => {
        //   Toast("请填写正确信息");
        // });
    },
  },
  created() {},
};
</script>

<style lang="less">
.main {
  height: 100%;
}
.login {
  position: absolute;
  top: 0px;
  left: 0px;
  background-color: #dc2c1f;
  width: 100%;
  height: 100vh;
  color: #fff;
  .IconLogo {
    width: 75px;
    height: 75px;
    border-radius: 50%;
    background-color: #f12a23;
    text-align: center;
    line-height: 75px;
    margin: 30% auto;
    i {
      font-size: 50px;
    }
  }
}
h1 {
  font-size: 48px;
  height: 48px;
  padding: 150px 0 40px 0;
}
.form {
  .item {
    width: 76%;
    height: 30px;
    line-height: 30px;
    margin: 0 auto;
    background-color: #f47378;
    border-radius: 30px;
    margin-bottom: 12px;
    input {
      background-color: transparent;
      border: 0px;
      outline: none;
      text-indent: 0.5em;
      font-size: 14px;
      color: #fff;
    }
    span {
      font-size: 20px;
      margin-left: 10px;
      display: inline-block;
      vertical-align: middle;
    }
    .getCode {
      border: 1px solid #fff;
      height: 20px;
      line-height: 20px;
      width: 50px;
      border-radius: 20px;
      font-size: 12px;
      color: #808080;
      float: right;
      margin: 5px;
    }
    .submit {
      font-size: 15px;
      background-color: #fff;
      text-align: center;
      color: #d4473c;
      border-radius: 15px;
    }
  }
}
.SwitchInputMode {
  width: 80%;
  margin: 40px auto;
  display: flex;
  justify-content: space-around;
  div {
    padding: 6px;
    border-radius: 50%;
    border: 1px solid #ffccce;
    color: #ffccce;
    font-size: 25px;
  }
}
.SkipValidation {
  width: 100%;
  margin: 20px auto;
  text-align: center;
  div{
    height: 30px;
    line-height: 30px;
    font-size: 15px;
    margin: 0px auto;
    width: 76%;
    border: 1px solid #ffccce;
    border-radius: 15px;
  }
}
</style>